<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        登入日志
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <!--导入ElementUI样式列表，css样式一般都在页面头部-->
    <link rel="stylesheet" th:href="@{/css/index.css}">
</head>
<style>
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
</style>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>日志管理</cite></a>
              <a><cite>登入日志</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="app-container" id="app">
        <div class="search-div">
            <el-form label-width="70px" size="small">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="关 键 字">
                            <el-input style="width: 95%" v-model="searchMap.keyword"
                                      placeholder="用户账号/登录IP地址"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="操作时间">
                            <el-date-picker
                                    v-model="createTimes"
                                    type="datetimerange"
                                    range-separator="至"
                                    start-placeholder="开始时间"
                                    end-placeholder="结束时间"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    style="margin-right: 10px;width: 100%;"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row style="display:flex">
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData(111)">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
                    <!--                    <el-button type="success" icon="el-icon-plus" size="mini" @click="add">添 加</el-button>-->
                </el-row>
                <el-divider></el-divider>
            </el-form>
        </div>
        <el-table
                :data="list"
                style="width: 100%"
                :row-class-name="tableRowClassName">
            <el-table-column
                    prop="username"
                    label="登入账号"
                    width="180" align="center">
            </el-table-column>
            <el-table-column
                    prop="ipaddr"
                    label="登录IP地址"
                    width="180" align="center">
            </el-table-column>
            <el-table-column
                    label="登录状态"
                    width="180" align="center">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.status==0">成功</el-tag>
                    <el-tag type="danger" v-if="scope.row.status==1">失败</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    prop="province"
                    label="访问地址" align="center">
            </el-table-column>
            <el-table-column
                    prop="msg"
                    label="提示信息" align="center">
            </el-table-column>
            <el-table-column
                    prop="createTime"
                    label="登入时间" align="center">
            </el-table-column>
        </el-table>
        <br/>
        <!-- 分页组件 -->
        <el-pagination
                background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :page-size="searchMap.limit"
                layout="prev, pager, next,sizes"
                :page-sizes="[5,10,20]"
                style="text-align: right;"
                :total="total">
        </el-pagination>
    </div>
</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<!--js脚本一般是放在页面尾部-->
<!--Vue js脚本-->
<script th:src="@{/js/vue.js}" charset="utf-8"></script>
<!--引入ElementUI组件库-->
<script th:src="@{/js/index.js}" charset="utf-8"></script>
<!--引入Axios js脚本-->
<script th:src="@{/js/axios.js}" charset="utf-8"></script>
<!--引入时间插件包Momentjs-->
<script th:src="@{/js/moment.min.js}" charset="utf-8"></script>

<script>
    var app = new Vue({
        el: "#app",//声明当前Vue在页面的作用域
        data: {
            listLoading: true,			// 数据是否正在加载
            list: null, 					// banner列表
            total: 0, 					// 数据库中的总记录数
            page: 1, 						// 默认页码
            limit: 2, 					// 每页记录数
            searchMap: {"createTimeBegin": "", "createTimeEnd": "", "keyword": this.keyword, "page": 1, "limit": 5},
            createTimes: []
        },
        methods: {
            //日期格式化方法
            //date 要进行格式的日期 ；format 格式化的样式
            dateFormat(date, format) {
                //默认格式化字符串"YYYY-MM-DD HH:mm:ss"
                if (format == null || format == '') {
                    format = "YYYY-MM-DD HH:mm:ss";
                }
                return moment(date).format(format);
            },
            tableRowClassName({row, rowIndex}) {
                if (row.status === 1) {
                    return 'warning-row';
                } else if (row.status === 0) {
                    return 'success-row';
                }
                return '';
            },
            // 加载banner列表数据
            fetchData(page) {
                if (page != null) {
                    this.searchMap.page = 1;
                }
                if (this.createTimes && this.createTimes.length == 2) {
                    this.searchMap.createTimeBegin = this.createTimes[0];
                    this.searchMap.createTimeEnd = this.createTimes[1];
                }
                axios.post("/loginlog/search", this.searchMap).then((res) => {
                    this.list = res.data.data.records;
                    for (var i = 0; i < this.list.length; i++) {
                        this.list[i].createTime=this.dateFormat(this.list[i].createTime);
                    }
                    this.total = res.data.data.total;
                    // 数据加载并绑定成功
                    this.listLoading = false;
                });
            },
            // 重置查询表单
            resetData() {
                console.log('重置查询表单');
                this.searchMap = {
                    "createTimeBegin": "",
                    "createTimeEnd": "",
                    "keyword": this.keyword,
                    "page": 1,
                    "limit": 5
                };
                this.createTimes = [];
                this.fetchData();
            },

            //handleSizeChange每页数量发生变化后触发的方法
            handleSizeChange(pageSize) {
                this.searchMap.limit = pageSize;
                this.fetchData();
            },
            //handleCurrentChange页码变化触发方法
            handleCurrentChange(pageNum) {
                this.searchMap.page = pageNum;
                this.fetchData();
            }
        },
        created: function () {//Vue生命周期方法，加载页面时会执行该方法
            layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
                $ = layui.jquery;//jquery
                layer = layui.layer;//弹出层
                okLoading.close($);
                layer.ready(function () { //为了layer.ext.js加载完毕再执行
                    layer.photos({
                        photos: '#x-img'
                    });
                });
            });
            this.fetchData();

        }
    });

</script>


</body>
</html>
